//
//  JZHPaiXu.m
//  极致荟
//
//  Created by hetao on 14-5-19.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHPaiXu.h"
#import "pinyin.h"
#import "OtherUsers.h"
@implementation JZHPaiXu
+ (JZHPaiXu *)shareArr:(NSArray *)arr
{
    JZHPaiXu *paixu=[[JZHPaiXu alloc]init];
    paixu.pingyin=[[NSMutableArray alloc]init];
    paixu.pingyinDic=[[NSMutableDictionary alloc]init];
    
    for( OtherUsers  *xin in arr )
    {
         char c;
        if(xin.bname.length!=0)
        {
            c=pinyinFirstLetter([xin.bname characterAtIndex:0]);
        }else
        {
            c=pinyinFirstLetter([xin.name characterAtIndex:0]);
        }
        
        NSLog(@"%d",c);
        NSString *str=[NSString stringWithFormat:@"%c",c] ;
        if(![paixu.pingyinDic objectForKey:str])
        {   [paixu.pingyin addObject:str];
            NSMutableArray *arr=[[NSMutableArray alloc]init];
            [arr addObject:xin];
            [paixu.pingyinDic setObject:arr forKey:str];
        }else
        {
            NSMutableArray *arr2=[paixu.pingyinDic objectForKey:str];
            [arr2 addObject:xin];
            [paixu.pingyinDic setObject:arr2 forKey:str];
        }
        
    }
//    if(paixu.pingyin.count<1)
//    {
//        return paixu;
//    }
    [paixu paixu:paixu.pingyin];
    return paixu;

}

///字母排序
- (void)paixu:(NSMutableArray *)arr
{
    if(arr.count<1)
    {
        return;
    }
    for(int i=0;i<arr.count-1;i++)
    {
        
        for(int j=0;j<arr.count-i-1;j++)
        {
            NSString* c1=arr[j];
            NSString* c2= arr[j+1] ;
            if([c2 characterAtIndex:0] <[c1 characterAtIndex:0])
            {
                
                [arr exchangeObjectAtIndex:j withObjectAtIndex:j+1];
                
                
            }
        }
        
        
    }
}

@end
